//
//  ComNoteImageScrollview.m
//  DogeLegs
//
//  Created by 宋华 on 2017/9/9.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "ComNoteImageScrollview.h"
#import "ImageMode.h"

#define kImageItemX_space 5

@interface ComNoteImageScrollview () {

}

@property (nonatomic,strong)NSMutableArray *noteImageViews;

@end

@implementation ComNoteImageScrollview


#pragma mark - lifeCircle
- (void)awakeFromNib {
    [super awakeFromNib];
}

#pragma mark -刷新
- (void)reloadImages {
    NSArray *temps = [self.noteImageViews copy];
    [self.noteImageViews removeAllObjects];
    for (NSInteger i = 0 ; i < self.noteImages.count; i ++) {
        UIImageView *curImgView = [temps getObjectAtIndex:i];
        ImageMode *imgMode = [self.noteImages getObjectAtIndex:i];
        if (!curImgView) {
            CGFloat x = i  * (kImageItemX_space +kImageItemWidth);
            curImgView = [[UIImageView alloc] initWithFrame:CGRectMake(x, 0, kImageItemWidth, kImageItemWidth)];
            [self addSubview:curImgView];
        }
        [curImgView sd_setImageWithURL:[NSURL URLWithString:imgMode.imageUrl] placeholderImage:[UIImage imageNamed:@"photo"]];

        [self.noteImageViews addObject:curImgView];
    }
    CGFloat conWidth = self.noteImageViews.count * (kImageItemX_space +kImageItemWidth);
    
    self.contentSize = CGSizeMake(conWidth, kImageItemWidth);
}

#pragma mark - setter
- (void)setNoteImages:(NSArray *)noteImages {
    if (_noteImages != noteImages) {
        _noteImages = noteImages;
        [self reloadImages];
    }
}

#pragma mark -getter
- (NSMutableArray *)noteImageViews {
    if (_noteImageViews == nil) {
        _noteImageViews = [NSMutableArray array];
    }
    return _noteImageViews;
}


@end
